<template>
  <div class="centent">
    <van-share-sheet
      v-model="showShare"
      title="立即分享给好友"
      :options="options"
    />

    <div class="cnetext-top">
      <span class="iconfont icon-zuojiantou" @click="fun1()"></span>
      <div class="cnetext-top-right">
        <span class="iconfont icon-kefu"></span>
        <span class="iconfont icon-fenxiang" @click="fun2()"></span>
        <span>求购</span>
      </div>
    </div>
    <div class="centents">
      <div class="GoMap">
        <van-swipe @change="onChange">
          <van-swipe-item><img v-lazy="RP.imgs" alt="" /></van-swipe-item>
          <van-swipe-item><img v-lazy="RP.imgs" alt="" /></van-swipe-item>
          <van-swipe-item><img v-lazy="RP.imgs" alt="" /></van-swipe-item>
          <van-swipe-item><img v-lazy="RP.imgs" alt="" /></van-swipe-item>
          <van-swipe-item><img v-lazy="RP.imgs" alt="" /></van-swipe-item>
          <van-swipe-item><img v-lazy="RP.imgs" alt="" /></van-swipe-item>
          <template #indicator>
            <div class="custom-indicator">{{ current + 1 }}/6</div>
          </template>
        </van-swipe>
      </div>

      <div class="centents1">
        <div>
          <span
            ><span class="price">{{ RP.price }}</span> 优惠价</span
          ><span>{{ RP.number }}人付款</span>
        </div>
        <p>{{ RP.classify }}</p>
        <nav>
          <span class="iconfont icon-dewu"></span> 先鉴别后发货 · 全新正品 ·
          假一赔三<span class="iconfont icon-youjiantou"></span>
        </nav>
        <div class="evaluate">
          <span>商品评价({{ RP.evaluate }})</span
          ><span class="iconfont icon-youjiantou" @click="fun4(RP)"></span>
        </div>
        <div class="evaluates">
          <button>偏小{{ RP.min }}</button>
          <button>合适{{ RP.fit }}</button>
          <button>偏大{{ RP.mix }}</button>
        </div>
      </div>
      <div class="publish">
        <div>
          <h3>穿搭评价</h3>
          <span>发布+</span>
        </div>
        <nav>
          <span>
            <img v-lazy="maps.map1.imgs" alt="" />
          </span>
          <div class="map01">
            <div>
              <img v-lazy="maps.map2.imgs" alt="" />
            </div>
            <div>
              <img v-lazy="maps.map3.imgs" alt="" />
            </div>
          </div>
        </nav>
        <p>查看全部 <span class="iconfont icon-youjiantou"></span></p>
      </div>
    </div>

    <div class="footer">
      <van-goods-action>
        <van-goods-action-icon icon="chat-o" text="客服" />
        <van-goods-action-icon icon="shop-o" text="店铺" />
        <van-goods-action-button
          color="#7232dd"
          type="warning"
          @click="fun6()"
          text="加入购物车"
        />
        <van-goods-action-button
          color="#7232dd"
          type="danger"
          @click="fun5()"
          text="立即购买"
        />
      </van-goods-action>
    </div>

    <!-- 显示购买 -->
    <van-action-sheet v-model="show" title="">
      <div class="content111">
        <div class="content111-top">
          <span>
            <img v-lazy="RP.imgs" alt="" />
          </span>
          <span>
            <p>{{ pitchOn.price }}</p>
            <br />
            已选 : {{ pitchOn.size }}
          </span>
        </div>
        <div class="content111-centent">
          <div @click="fun7(i)" v-for="(v, i) in sizex" :key="i" ref="bor">
            <span>{{ v.szie }}</span>
            <p>￥{{ v.price }}</p>
          </div>
          
        </div>
        <button class="gouwuche" @click="open2()" ref="gouwuche">
            加入购物车 <span>|</span> {{ pitchOn.price }}
          </button>
          <button class="mai" @click="fun8()">
            购买 <span>|</span> {{ pitchOn.price }}
          </button>
      </div>
    </van-action-sheet>
    <div class="edition" v-for="(v, i) in edition" :key="i">
      <img v-lazy="v.imgs" alt="" />
    </div>
  </div>
</template>

<script>
import { GoodsAction, GoodsActionIcon, GoodsActionButton } from "vant";

Vue.use(GoodsAction);
Vue.use(GoodsActionButton);
Vue.use(GoodsActionIcon);
import { Button } from "vant";
import getLink from "../../apis/getapi";
Vue.use(Button);
import { Field } from "vant";
Vue.use(Field);
import Vue from "vue";
import { ShareSheet } from "vant";
import "vant/lib/index.css";
Vue.use(ShareSheet);
import { ActionSheet } from "vant";
Vue.use(ActionSheet);
import { Uploader } from "vant";
Vue.use(Uploader);
import postapi from "../../apis/postapi.js"
export default {
  created() {
    
    this.RP = JSON.parse(this.$route.query.RPid);
    this.sizex = this.RP.yardage;
    //第一次默认的
    this.pitchOn.size = this.sizex[0].szie;
    this.pitchOn.price = "￥" + this.sizex[0].price;
    this.pitchOn.imgs = this.sizex[0].imgs;
    this.pitchOn.classify = this.sizex[0].classify;
    getLink("/Purchase/CommentMap").then((ok) => {
      this.maps = ok.data.map;
      this.edition = ok.data.maps;
    });
   
  },
  methods: {
    open2() {
       
      this.$message({
        message: "添加成功",
        type: "success",
      });
       let arrs = this.sizex[this.ids]

       //post请求
      postapi("/goshopping",arrs).then((ok)=>{
        console.log(ok);
        alert("加入成功")
      }).catch((err)=>{
        console.log(err);
        alert("加入失败")
      })
    },
    fun8() {
      this.$router.push({
        name: "OrderForm",
        query: { OrderForm: JSON.stringify(this.pitchOn) },
      });
    },
    //购买
    fun7(index) {
      for (var i = 0; i < this.sizex.length; i++) {
        if (i !== index) {
          //没选中
          this.$refs.bor[i].style.border = "";
        } else {
          //选中
          // console.log(this.$refs.bor[i]);
          this.$refs.bor[i].style.border = "0.01rem solid black";
          this.pitchOn.size = this.$refs.bor[i].childNodes[0].innerHTML;
          this.pitchOn.price = this.$refs.bor[i].childNodes[1].innerHTML;
          this.pitchOn.imgs = this.RP.yardage[i].imgs;
          this.pitchOn.classify = this.RP.yardage[i].classify;
           this.ids = i;
        }
      }
    },
    fun1() {
      this.$router.go(-1);
    },
    onChange(index) {
      this.current = index;
    },
    fun2() {
      this.showShare = true;
    },
    fun4() {
      this.$router.push({
        name: "Pj",
        query: { Pjid: JSON.stringify(this.RP) },
      });
    },
    fun5() {
      this.show = true;
    },
    fun6() {
      this.show = true;
    },
  },
  data() {
    return {
      ids:0,
      pitchOn: { size: 123, price: 123, imgs: "", classify: "" },
      sizex: [],
      borderx: "0.01rem solid white",
      shoucang: "收藏",
      edition: [],
      message: "",
      maps: "",
      show: false,
      current: 0,
      RP: [],
      showShare: false,
      imgx: [],
      options: [
        [
          { name: "微信", icon: "wechat" },
          { name: "朋友圈", icon: "wechat-moments" },
          { name: "微博", icon: "weibo" },
          { name: "QQ", icon: "qq" },
        ],
        [
          { name: "复制链接", icon: "link" },
          { name: "分享海报", icon: "poster" },
          { name: "二维码", icon: "qrcode" },
          { name: "小程序码", icon: "weapp-qrcode" },
        ],
      ],
      fileList: [{ url: "https://cloud-image", isImage: true }],
    };
  },
};
</script>

<style scoped>
.gouwuche span {
  color: rgba(241, 241, 241, 0.486);
  font-size: 0.16rem;
}
.gouwuche {
  width: 2rem;
  height: 0.5rem;
  line-height: 0.5rem;
  text-align: center;
  color: white;
  font-weight: bold;
  border: none;
  background: #05cd91;
  margin-top: 0.5rem;
  margin-bottom: 0.1rem;
}
.mai span {
  color: rgba(241, 241, 241, 0.486);
  font-size: 0.16rem;
}
.mai {
  width: 2rem;
  height: 0.5rem;
  line-height: 0.5rem;
  text-align: center;
  color: white;
  font-weight: bold;
  border: none;
  background: #05cd91;
  margin-top: 0.3rem;
  margin-bottom: 0.5rem;
}
.content111 {
  padding: 0.1rem;
}
.content111-centent {
  width: 100%;
  margin: auto;
  min-height: 2rem;
  display: flex;
  flex-wrap: wrap;
  background: rgb(247, 245, 245);
}
.content111-centent div {
  width: 20%;
  height: 0.6rem;
  text-align: center;
  margin: 0.05rem;
  line-height: 0.3rem;
  background: white;
}
.content111-centent div span {
  font-weight: bold;
}
.content111-top {
  width: 90%;
  margin: auto;
  height: 1rem;
  display: flex;
  justify-content: space-around;
}
.content111-top span:nth-child(1) {
  width: 0.8rem;
  height: 0.8rem;
}
.content111-top span:nth-child(2) {
  flex: 1;
  margin-left: 0.3rem;
}
.content111-top span:nth-child(2) p {
  font-size: 0.24rem;
  font-weight: bold;
}
.content111-top img {
  width: 100%;
  height: 100%;
}
.edition {
  width: 100%;
  margin: auto;
  height: auto;
  margin-bottom: 1rem;
}
.edition img {
  width: 100%;
}
.bt {
  position: absolute;
  bottom: 0.2rem;
  right: 40%;
}
.content222 {
  margin-bottom: 0.2rem;
}

.publish p {
  width: 100%;
  height: 0.3rem;
  text-align: center;
  color: rgb(173, 169, 169);
  line-height: 0.3rem;
  margin-bottom: 0.1rem;
}
.publish p .icon-youjiantou {
  color: rgb(173, 169, 169);
}
.publish {
  width: 100%;
  min-height: 2rem;
  margin-top: 0.2rem;
}
.publish div:nth-child(1) {
  display: flex;
  width: 100%;
  justify-content: space-between;
}
.publish div:nth-child(1) span {
  color: rgb(192, 189, 189);
}
.publish nav {
  width: 100%;
  display: flex;
  margin-top: 0.2rem;
  flex-wrap: wrap;
}
.publish nav span {
  width: 65%;
  height: 45%;
}
.publish nav .map01 {
  width: 30%;
}
.publish nav .map01 div {
  width: 100%;
  height: 49%;
}
.publish nav img {
  width: 100%;
  height: 100%;
  border: 0.01rem solid white;
  box-sizing: border-box;
}
.evaluates {
  display: flex;
  width: 100%;
  height: 0.2rem;
  justify-content: space-between;
  margin: 0rem !important;
}
.evaluates button {
  width: 0.8rem;
  border: none;
  height: 0.3rem;
}
.evaluate {
  display: flex;
  width: 100%;
  height: 0.2rem;
  justify-content: space-between;
  font-size: 0.18rem;
}
.evaluate span {
  font-size: 0.16rem;
  font-weight: bold;
}
.evaluate .icon-youjiantou {
  color: rgb(119, 117, 117);
  font-size: 0.18rem;
}
.custom-indicator {
  position: absolute;
  right: 0.05rem;
  bottom: 0.05rem;
  padding: 0.02rem 0.05rem;
  font-size: 0.12rem;
  background: rgba(0, 0, 0, 0.1);
}
.centents1 div {
  width: 100%;
  display: flex;
  justify-content: space-between;
  height: 0.5rem;
  margin-top: 0.5rem;
}

.centents1 nav {
  width: 100%;
  background: turquoise;
  background-image: linear-gradient(to left, rgb(95, 124, 116), turquoise);
  height: 0.4rem;
  color: white;
  font-size: 0.16rem;
  font-weight: bolder;
  line-height: 0.4rem;
  display: flex;
  justify-content: space-around;
}
.icon-youjiantou {
  color: white;
  font-size: 0.1rem;
}
.icon-dewu {
  font-weight: normal;
}
.centents1 p {
  min-height: 0.3rem;
  font-size: 0.18rem;
}
.price {
  font-size: 0.18rem;
  font-weight: bolder;
}
.GoMap {
  width: 50%;
  height: 2rem;
  margin: auto;
  margin-top: 1rem;
}
.GoMap img {
  width: 100%;
  height: 100%;
}
.centent {
  height: 100vh;
  overflow: scroll;
  width: 90%;
  position: relative;
  margin: auto;
  display: flex;
  flex-direction: column;
}
.centents {
  flex: 1;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}
.cnetext-top {
  width: 100%;
  height: 0.8rem;
  line-height: 0.8rem;
  display: flex;
  justify-content: space-between;
  position: fixed;
  top: 0rem;
  left: 0rem;
  z-index: 99;
  background-color: white;
}
.cnetext-top-right {
  margin-right: 0.3rem;
}
.footer {
  width: 90%;
  height: 0.6rem;
  background: white;
  z-index: 999;
  position: fixed;
  bottom: -0.01rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  line-height: 0.3rem;
  border-top: 0.01rem solid rgb(212, 207, 207);
}

.icon-zuojiantou {
  font-size: 0.24rem;
  font-weight: bolder;
  margin-left: 0.2rem;
}
.cnetext-top div {
  width: 1.3rem;
  display: flex;
  justify-content: space-between;
  font-size: 0.18rem;
  font-weight: bolder;
}
</style>